<?php

define('NV_SYSTEM', true);
@require_once("mainfile.php");
$index = 1;
include("header.php");

if(defined('IS_ADMIN')) {
$oldyear = 10; // Thay doi thong so nam

if($_POST['submit'] !="") {
	$day = intval($_POST['day']);	
	$month = intval($_POST['month']);
	$year = intval($_POST['year']);
	$hour = intval($_POST['hour']);
	$minut = intval($_POST['minut']);
	$second = intval($_POST['second']);
	$sid = intval($sid);
	
	if(empty($sid) || empty($day) || empty($month) || $db->sql_numrows($db->sql_query("SELECT sid FROM ".$prefix."_stories WHERE sid='$sid'")) == 0) {
		echo "<br><center><font color=\"red\">Th&#244;ng s&#7889; kh&#244;ng ch&#237;nh x&#225;c, vui l&#242;ng ki&#7875;m tra l&#7841;i</font></center><br>";
		$error = 1;
	}	
	
	if(!$error) {
	if($day < 10) { $day = "0".$day.""; }
	if($month < 10) { $month = "0".$month.""; }
	if($hour < 10) { $hour = "0".$hour.""; }
	if($minut < 10) { $minut = "0".$minut.""; }
	if($second < 10) { $second = "0".$second.""; }
	
	$time_update  = "$year-$month-$day $hour:$minut:$second";
	
	$res = $db->sql_query("UPDATE ".$prefix."_stories SET time='$time_update' WHERE sid='$sid'");
	
	if($res) {
		OpenTable();
		echo "<center>C&#7853;p nh&#7853;t th&#224;nh c&#244;ng!<br><br><a href=\"update_timer.php\">Ti&#7871;p t&#7909;c</a></center>";
		CloseTable();
		include("footer.php");
		exit;	
	} else {
		OpenTable();
		echo "<center>C&#243; l&#7895;i x&#7843;y ra.</center>";
		CloseTable();
		include("footer.php");
		exit;	
	}
}
}	

OpenTable();
$today = getdate();
$tyear = $today[year];
echo "<center><form method=\"POST\"><table border=\"0\" cellpadding=\"3\">\n";
echo "	<tr>\n";
echo "		<td>Th&#7901;i gian:</td>\n";
echo "		<td>";
echo "<select name=\"day\">";
echo "<option value=\"\">Ng&#224;y</option>";
for($i =1; $i < 32; $i ++) {
	echo "<option value=\"$i\">$i</option>";
}	
echo "</select>";
echo "</td>\n";
echo "		<td>";
echo "<select name=\"month\">";
echo "<option value=\"\">Th&#225;ng</option>";
for($i =1; $i <= 12; $i ++) {
	echo "<option value=\"$i\">$i</option>";
}	
echo "</select>";
echo "</td>\n";
echo "		<td>";
echo "<select name=\"year\">";
echo "<option value=\"$tyear\"selected>$tyear</option>";
	for($i = 0; $i < $oldyear; $i ++) {
	    $xi = $tyear - $i -1;
		echo "<option value=\"$xi\">$xi</option>";
	}
echo "</select>";
echo "</td>\n";
echo "		<td>";
echo "<select name=\"hour\">";
echo "<option value=\"\">Gi&#7901;</option>";
for($i = 0; $i < 24; $i ++) {
	echo "<option value=\"$i\">$i</option>";
}	
echo "</select>";
echo "</td>\n";
echo "		<td>";
echo "<select name=\"minut\">";
echo "<option value=\"\">Ph&#250;t</option>";
for($i = 1; $i < 60; $i ++) {
	echo "<option value=\"$i\">$i</option>";
}	
echo "</select>";
echo "</td>\n";
echo "		<td>";
echo "<select name=\"second\">";
echo "<option value=\"\">Gi&#226;y</option>";
for($i = 1; $i < 60; $i ++) {
	echo "<option value=\"$i\">$i</option>";
}	
echo "</select>";
echo "</td></tr></table>\n";
echo "<table border=\"0\"><tr>";
echo "<td>S&#7889; ID b&#224;i vi&#7871;t:</td><td><input type=\"text\" name=\"sid\" size=\"10\" maxlength=\"11\"></td><td><input type=\"submit\" name=\"submit\" value=\"C&#7853;p nh&#7853;t\"></td>\n";
echo "	</tr>\n";
echo "</table></form></center>\n";

CloseTable();
} else {
	OpenTable();
	echo "<center><b>Ban khong duoc phep truy cap vao khu vuc nay!</b></center>";
	CloseTable();	
}	
include("footer.php");

?>